const {NAME_AND_PASSWORD_IS_REQUIRED,NAME_REQURIED}=require('../error/errorType')
const serviceSql=require('../service/service')

const verifyRegister=async(ctx,next)=>{
    let {name,password}=ctx.request.body
    if(!name || !password){
        return ctx.app.emit('error',new Error(NAME_AND_PASSWORD_IS_REQUIRED),ctx)
    }
    let result=await serviceSql.login(name)
    if(result.length){
        return ctx.app.emit('error',new Error(NAME_REQURIED),ctx)
    }
    await next()
}

module.exports={
    verifyRegister
}